//
//  DXNavigationController.swift
//  weiBoOfSwift
//
//  Created by simon on 15/12/5.
//  Copyright © 2015年 simon. All rights reserved.
//

import UIKit

class DXNavigationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
      
        


    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        
//        logPrint(childViewControllers)
        
        if childViewControllers.count > 0 {
            
            viewController.hidesBottomBarWhenPushed = true
        
        let leftTitle = UIBarButtonItem.customItem(title: childViewControllers.first!.title, imgName: "navigationbar_back_withtext", target: self, action: "backBtnClick")
        
        let leftBack = UIBarButtonItem.customItem(title: "返回", imgName: "navigationbar_back_withtext", target: self, action: "backBtnClick")
        
        viewController.navigationItem.leftBarButtonItem = (childViewControllers.count != 1) ? leftBack:leftTitle
        
        viewController.navigationItem.rightBarButtonItem = UIBarButtonItem.customItem(title: "PUSH", target: self, action: "pushBtnClick")
        
        viewController.title = "当前是第\(childViewControllers.count + 1)级控制器"
        }
        super.pushViewController(viewController, animated: animated)
    }

    // MARK: - pushClick点击事件
    @objc private func pushBtnClick(){
        
        let currentController = DXTempViewController()
       
     pushViewController(currentController, animated: true)
        
        
    }
    // MARK: - backBtnClick点击事件
    @objc private func backBtnClick(){
        popViewControllerAnimated(true)
        
    }
    
  func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool{
    
//    logPrint("******")
    return childViewControllers.count != 1
    }
    
 
//    hidesBottomBarWhenPushed
 
  
}
